FUNDAMENTALS OF ARTIFICIAL INTELLIGENCE – PRACTICAL CODES
Windows-readable TXT format
======================================================================

#S11
----------
#S11

age = 20

if age >= 18:
    print("You are eligible to vote")
    print("You are an adult")

OUTPUT:
You are eligible to vote
You are an adult

======================================================================

#S13
----------
#S13

room = input("Enter room status (clean/dirty): ")
memory = input("Enter previous status (clean/dirty): ")

if room == "dirty":
    print("Action: Clean the room")
elif room == "clean" and memory == "dirty":
    print("Action: Check the room again")
else:
    print("Action: Do nothing")

OUTPUT:
Enter room status (clean/dirty):  clean
Enter previous status (clean/dirty):  clean

OUTPUT:
Action: Do nothing

======================================================================

#S21
----------
#S21

def hanoi(n, source, helper, destination):
    if n == 1:
        print("Move disk from", source, "to", destination)
        return

    hanoi(n - 1, source, destination, helper)
    print("Move disk from", source, "to", destination)
    hanoi(n - 1, helper, source, destination)

n = 3
hanoi(n, "A", "B", "C")

OUTPUT:
Move disk from A to C
Move disk from A to B
Move disk from C to B
Move disk from A to C
Move disk from B to A
Move disk from B to C
Move disk from A to C

======================================================================

#S22
----------
#S22

def minimax(depth, node, maximizing):
    if depth == 0:
        return node

    if maximizing:
        return max(
            minimax(depth - 1, node - 2, False),
            minimax(depth - 1, node + 2, False)
        )
    else:
        return min(
            minimax(depth - 1, node - 2, True),
            minimax(depth - 1, node + 2, True)
        )

value = minimax(2, 5, True)

print("Best value:", value)

OUTPUT:
Best value: 5

======================================================================

#S31
----------
#S31

temperature = int(input("Enter temperature: "))

if temperature > 30:
    print("Fan ON")
else:
    print("Fan OFF")

OUTPUT:
Enter temperature:  34

OUTPUT:
Fan ON

======================================================================

#S33
----------
#S33

def solve(board, row, n):
    if row == n:
        print(board)
        return True

    for col in range(n):
        if col not in board:
            board.append(col)

            if solve(board, row + 1, n):
                return True

            board.pop()

    return False


n = 4
solve([], 0, n)

OUTPUT:
[0, 1, 2, 3]

OUTPUT:
True

======================================================================

#S41
----------
#S41

from sklearn.linear_model import LogisticRegression

x = [[10], [15], [17], [18], [20], [25], [30]]
y = [0, 0, 0, 1, 1, 1, 1]

model = LogisticRegression()
model.fit(x, y)

age = int(input("Enter age: "))

result = model.predict([[age]])

if result[0] == 1:
    print("Eligible to vote")
else:
    print("Not eligible to vote")

OUTPUT:
Enter age:  34

OUTPUT:
Eligible to vote

======================================================================

#S43
----------
#S43

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("iris.csv")

plt.scatter(df["sepal_length"], df["sepal_width"])

plt.xlabel("Sepal Length")
plt.ylabel("Sepal Width")
plt.title("Sepal Length vs Sepal Width")

plt.show()

======================================================================

#S51
----------
#S51

monkey = "door"
banana = "center"
box = "window"

print("Monkey is at", monkey)

if monkey != box:
    print("Monkey moves to the box")
    monkey = box

print("Monkey pushes the box")

monkey = banana

print("Monkey climbs on the box")
print("Monkey gets the banana")

if monkey == banana:
    print("Goal achieved")

OUTPUT:
Monkey is at door
Monkey moves to the box
Monkey pushes the box
Monkey climbs on the box
Monkey gets the banana
Goal achieved

======================================================================

#S53
----------
#S53

while True:

    user = input("You: ")

    if user.lower() == "hello":
        print("Bot: Hello!")

    elif user.lower() == "how are you":
        print("Bot: I am fine.")

    elif user.lower() == "bye":
        print("Bot: Goodbye!")
        break

    else:
        print("Bot: I don't understand.")

OUTPUT:
You:  hi

OUTPUT:
Bot: I don't understand.

OUTPUT:
You:  hello

OUTPUT:
Bot: Hello!

OUTPUT:
You:  bye

OUTPUT:
Bot: Goodbye!

======================================================================

#S61
----------
#S61

numbers = [2, 5, 8, 6, 10, 7]

current = 0

while current < len(numbers) - 1:

    if numbers[current + 1] > numbers[current]:
        current = current + 1
    else:
        break

print("Best value:", numbers[current])

OUTPUT:
Best value: 8

======================================================================

#S62
----------
#S62

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("iris.csv")

plt.scatter(df["petal_length"], df["petal_width"])

plt.xlabel("Petal Length")
plt.ylabel("Petal Width")
plt.title("Petal Length vs Petal Width")

plt.show()

======================================================================

#S71
----------
#S71

import pandas as pd

data = {
    "Name": ["Rahul", "Amit", "Karan", "Riya"],
    "Department": ["IT", "HR", "IT", "IT"],
    "Salary": [60000, 40000, 55000, 70000]
}

df = pd.DataFrame(data)

result = df[
    (df["Department"] == "IT") &
    (df["Salary"] > 50000) &
    (df["Name"].str.contains("a", case=False))
]

print(result)

OUTPUT:
    Name Department  Salary
0  Rahul         IT   60000
2  Karan         IT   55000
3   Riya         IT   70000

======================================================================

#S72
----------
#S72

previous = input("Enter previous door status: ").upper()
current = input("Enter current door status: ").upper()

if previous not in ["OPEN", "CLOSED"] or current not in ["OPEN", "CLOSED"]:
    print("Invalid input")

elif previous == "CLOSED" and current == "OPEN":
    print("Action: Send security alert")

elif previous == "OPEN" and current == "CLOSED":
    print("Action: Door closed")

else:
    print("Action: No change")

OUTPUT:
Enter previous door status:  open
Enter current door status:  open

OUTPUT:
Action: No change

======================================================================

#S81
----------
#S81

monkey = "door"
box = "window"
banana = "center"

print("Monkey is at", monkey)

if monkey != box:
    print("Monkey moves to box")
    monkey = box

print("Monkey pushes box towards banana")
monkey = banana

print("Monkey climbs on box")
print("Monkey gets banana")

if monkey == banana:
    print("Goal achieved")

OUTPUT:
Monkey is at door
Monkey moves to box
Monkey pushes box towards banana
Monkey climbs on box
Monkey gets banana
Goal achieved

======================================================================

#S83
----------
#S83

import pandas as pd

data = {
    "Name": ["Amit", "Riya", "Karan", "Neha"],
    "Salary": [30000, 40000, 50000, 35000],
    "Experience": [2, 5, 1, 4]
}

df = pd.DataFrame(data)

for i in range(len(df)):

    if df.loc[i, "Experience"] < 3:
        df.loc[i, "Salary"] = df.loc[i, "Salary"] * 1.10
    else:
        df.loc[i, "Salary"] = df.loc[i, "Salary"] * 1.05

print(df)

OUTPUT:
    Name   Salary  Experience
0   Amit  33000.0           2
1   Riya  42000.0           5
2  Karan  55000.0           1
3   Neha  36750.0           4

OUTPUT:
C:\Users\piyus\AppData\Local\Temp\ipykernel_27000\2386889980.py:16: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '55000.00000000001' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
  df.loc[i, "Salary"] = df.loc[i, "Salary"] * 1.10

======================================================================

#S91
----------
#S91

import pandas as pd

data = {
    "Name": ["Amit", "Riya", "Karan", "Neha"],
    "Age": [25, 20, 30, 22]
}

df = pd.DataFrame(data)

df = df.sort_values("Age")

print(df)

OUTPUT:
    Name  Age
1   Riya   20
3   Neha   22
0   Amit   25
2  Karan   30

======================================================================

#S92
----------
#S92

blocks = ["A", "B", "C"]

print("Initial state:")
print(blocks)

print("Move A onto B")
blocks.remove("A")
blocks.insert(1, "A")

print(blocks)

print("Move C onto A")
blocks.remove("C")
blocks.append("C")

print(blocks)

print("Goal state achieved")

OUTPUT:
Initial state:
['A', 'B', 'C']
Move A onto B
['B', 'A', 'C']
Move C onto A
['B', 'A', 'C']
Goal state achieved

======================================================================

#S101
----------
#S101

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

data = load_iris()

x = data.data
y = data.target

print("Original data:", x.shape)

x_train, x_test, y_train, y_test = train_test_split(
    x, y, test_size=0.2
)

print("Training data:", x_train.shape)
print("Testing data:", x_test.shape)

OUTPUT:
Original data: (150, 4)
Training data: (120, 4)
Testing data: (30, 4)

======================================================================

#S102
----------
#S102

def solve(board, row, n):

    if row == n:
        print(board)
        return True

    for col in range(n):

        if col not in board:
            board.append(col)

            if solve(board, row + 1, n):
                return True

            board.pop()

    return False


n = 4

solve([], 0, n)

OUTPUT:
[0, 1, 2, 3]

OUTPUT:
True

======================================================================

#S111
----------
#S111

import pandas as pd
from sklearn.linear_model import LinearRegression

df = pd.read_csv("salary_data.csv")

x = df[["YearsExperience"]]
y = df["Salary"]

model = LinearRegression()
model.fit(x, y)

years = float(input("Enter years of experience: "))

salary = model.predict([[years]])

print("Predicted Salary:", salary[0])

#Import Salary CSV file

======================================================================

#S112
----------
#S112

from sklearn.linear_model import LogisticRegression

x = [
    [100, 2, 10, 80, 0],
    [5000, 1, 23, 20, 1],
    [200, 5, 12, 90, 0],
    [7000, 1, 2, 10, 1],
    [300, 4, 15, 85, 0]
]

y = [0, 1, 0, 1, 0]

model = LogisticRegression()
model.fit(x, y)

amount = float(input("Transaction Amount: "))
age = float(input("Card Age: "))
time = int(input("Transaction Time: "))
location = float(input("Location Match Score: "))
online = int(input("Online Transaction (1/0): "))

result = model.predict([[amount, age, time, location, online]])

if result[0] == 1:
    print("Fraud Transaction")
else:
    print("Legitimate Transaction")

OUTPUT:
Transaction Amount:  500
Card Age:  2
Transaction Time:  1
Location Match Score:  6
Online Transaction (1/0):  1

OUTPUT:
Legitimate Transaction

======================================================================

#S121
----------
#S121

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("car_data.csv")

plt.scatter(df["Car_Age"], df["Selling_Price"])

plt.xlabel("Car Age")
plt.ylabel("Selling Price")
plt.title("Car Age vs Selling Price")

plt.show()

#Import CSV car dataset

======================================================================

#S123
----------
#S123

location = input("Enter location (A/B): ").upper()
status = input("Enter room status (Clean/Dirty): ").lower()

if status == "dirty":
    print("Action: Clean the room")

elif location == "A":
    print("Action: Move to room B")

elif location == "B":
    print("Action: Move to room A")

else:
    print("Invalid input")

OUTPUT:
Enter location (A/B):  a
Enter room status (Clean/Dirty):  dirty

OUTPUT:
Action: Clean the room

======================================================================

#S131
----------
#S131

a = float(input("Enter first number: "))
b = float(input("Enter second number: "))

print("Sum =", a + b)
print("Difference =", a - b)
print("Product =", a * b)

if b != 0:
    print("Division =", a / b)
else:
    print("Cannot divide by zero")

OUTPUT:
Enter first number:  1
Enter second number:  2

OUTPUT:
Sum = 3.0
Difference = -1.0
Product = 2.0
Division = 0.5

======================================================================

#S133
----------
#S133

students = {}

n = int(input("Enter number of students: "))

for i in range(n):

    name = input("Enter student name: ")
    percentage = float(input("Enter percentage: "))

    students[name] = percentage

topper = max(students, key=students.get)

print("Student Records:")
print(students)

print("Topper:", topper)
print("Percentage:", students[topper])

OUTPUT:
Enter number of students:  3
Enter student name:  Piyush 
Enter percentage:  56
Enter student name:  Rakesh
Enter percentage:  45
Enter student name:  Purvesh
Enter percentage:  35

OUTPUT:
Student Records:
{'Piyush ': 56.0, 'Rakesh': 45.0, 'Purvesh': 35.0}
Topper: Piyush 
Percentage: 56.0

======================================================================

#S141
----------
#S141

name = input("Enter employee name: ")
number = input("Enter employee number: ")
salary = float(input("Enter salary: "))

print("\nEmployee Details")
print("----------------")
print("Name:", name)
print("Employee Number:", number)
print("Salary:", salary)

OUTPUT:
Enter employee name:  Piyush
Enter employee number:  1
Enter salary:  13456678

OUTPUT:

Employee Details
----------------
Name: Piyush
Employee Number: 1
Salary: 13456678.0

======================================================================

#S143
----------
#S143

def simple_interest(p, r, t):
    return (p * r * t) / 100


def compound_interest(p, r, t):
    return p * (1 + r / 100) ** t - p


p = float(input("Enter principal: "))
r = float(input("Enter rate: "))
t = float(input("Enter time: "))

si = simple_interest(p, r, t)
ci = compound_interest(p, r, t)

print("Simple Interest =", si)
print("Compound Interest =", ci)
print("Difference =", ci - si)

OUTPUT:
Enter principal:  300
Enter rate:  6000
Enter time:  4

OUTPUT:
Simple Interest = 72000.0
Compound Interest = 4153752000.0
Difference = 4153680000.0

======================================================================

#S151
----------
#S151

text = input("Enter a string: ")

vowels = 0
consonants = 0
digits = 0
special = 0

for ch in text:

    if ch.lower() in "aeiou":
        vowels += 1

    elif ch.isalpha():
        consonants += 1

    elif ch.isdigit():
        digits += 1

    else:
        special += 1

print("Vowels =", vowels)
print("Consonants =", consonants)
print("Digits =", digits)
print("Special Characters =", special)

OUTPUT:
Enter a string:  Piyush

OUTPUT:
Vowels = 2
Consonants = 4
Digits = 0
Special Characters = 0

======================================================================

#S153
----------
#S153

import numpy as np

data = np.array([10, 20, 30, 40, 50])

print("Minimum =", np.min(data))
print("Maximum =", np.max(data))
print("Mean =", np.mean(data))
print("Median =", np.median(data))
print("Standard Deviation =", np.std(data))

OUTPUT:
Minimum = 10
Maximum = 50
Mean = 30.0
Median = 30.0
Standard Deviation = 14.142135623730951

======================================================================

#S161
----------
#S161

numbers = (10, 20, 30, 40, 50)

print("Tuple:", numbers)
print("Largest =", max(numbers))
print("Smallest =", min(numbers))
print("Average =", sum(numbers) / len(numbers))

OUTPUT:
Tuple: (10, 20, 30, 40, 50)
Largest = 50
Smallest = 10
Average = 30.0

======================================================================

#S163
----------
#S163

d1 = {
    "A": 10,
    "B": 20,
    "C": 30
}

d2 = {
    "B": 5,
    "C": 10,
    "D": 40
}

result = d1.copy()

for key in d2:

    if key in result:
        result[key] = result[key] + d2[key]
    else:
        result[key] = d2[key]

print("Updated Dictionary:")
print(result)

OUTPUT:
Updated Dictionary:
{'A': 10, 'B': 25, 'C': 40, 'D': 40}

======================================================================

#S171
----------
#S171

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

iris = load_iris()

x = iris.data
y = iris.target

x_train, x_test, y_train, y_test = train_test_split(
    x, y, test_size=0.2
)

print("X_train shape:", x_train.shape)
print("X_test shape:", x_test.shape)

OUTPUT:
X_train shape: (120, 4)
X_test shape: (30, 4)

======================================================================

#S172
----------
#S172

previous = int(input("Enter previous traffic density: "))
current = int(input("Enter current traffic density: "))

if current > previous:
    print("Action: Keep signal GREEN for longer")

elif current < previous:
    print("Action: Reduce green signal time")

else:
    print("Action: Keep normal signal time")

OUTPUT:
Enter previous traffic density:  1
Enter current traffic density:  3

OUTPUT:
Action: Keep signal GREEN for longer

======================================================================

#S181
----------
#S181

text = input("Enter a string: ")

reverse = text[::-1]

if text == reverse:
    print("Palindrome")
else:
    print("Not Palindrome")

OUTPUT:
Enter a string:  Hii

OUTPUT:
Not Palindrome

======================================================================

#S182
----------
#S182

import pandas as pd

data = {
    "Name": ["Amit", "Riya", "Karan", "Neha"],
    "Salary": [30000, 60000, 45000, 70000],
    "Department": ["HR", "IT", "IT", "Sales"]
}

df = pd.DataFrame(data)

print("Original DataFrame:")
print(df)

print("\nSorted by Salary:")
print(df.sort_values("Salary"))

print("\nEmployees with Salary > 50000:")
print(df[df["Salary"] > 50000])

df["Salary"] = df["Salary"] + 5000

print("\nUpdated DataFrame:")
print(df)

OUTPUT:
Original DataFrame:
    Name  Salary Department
0   Amit   30000         HR
1   Riya   60000         IT
2  Karan   45000         IT
3   Neha   70000      Sales

Sorted by Salary:
    Name  Salary Department
0   Amit   30000         HR
2  Karan   45000         IT
1   Riya   60000         IT
3   Neha   70000      Sales

Employees with Salary > 50000:
   Name  Salary Department
1  Riya   60000         IT
3  Neha   70000      Sales

Updated DataFrame:
    Name  Salary Department
0   Amit   35000         HR
1   Riya   65000         IT
2  Karan   50000         IT
3   Neha   75000      Sales

======================================================================

#S191
----------
#S191

import pandas as pd

data = {
    "Name": ["Amit", "Riya", "Karan", "Neha"],
    "Age": [25, 20, 30, 22]
}

df = pd.DataFrame(data)

print("Original DataFrame:")
print(df)

df = df.sort_values("Age")

print("\nSorted DataFrame:")
print(df)

OUTPUT:
Original DataFrame:
    Name  Age
0   Amit   25
1   Riya   20
2  Karan   30
3   Neha   22

Sorted DataFrame:
    Name  Age
1   Riya   20
3   Neha   22
0   Amit   25
2  Karan   30

======================================================================

#S193
----------
#S193

from sklearn.linear_model import LogisticRegression

x = [
    [100, 2, 10, 80, 0],
    [5000, 1, 23, 20, 1],
    [200, 5, 12, 90, 0],
    [7000, 1, 2, 10, 1],
    [300, 4, 15, 85, 0]
]

y = [0, 1, 0, 1, 0]

model = LogisticRegression()
model.fit(x, y)

amount = float(input("Transaction Amount: "))
age = float(input("Card Age: "))
time = int(input("Transaction Time: "))
location = float(input("Location Match Score: "))
online = int(input("Online Transaction (0/1): "))

result = model.predict([[amount, age, time, location, online]])

if result[0] == 1:
    print("Fraud")
else:
    print("Legit")

OUTPUT:
Transaction Amount:  4000
Card Age:  4
Transaction Time:  5
Location Match Score:  1
Online Transaction (0/1):  1

OUTPUT:
Fraud

======================================================================

#S201
----------
#S201

import pandas as pd
from sklearn.linear_model import LinearRegression

df = pd.read_csv("advertising.csv")

x = df[["TV", "Radio", "Newspaper"]]
y = df["Sales"]

model = LinearRegression()
model.fit(x, y)

tv = float(input("Enter TV budget: "))
radio = float(input("Enter Radio budget: "))
newspaper = float(input("Enter Newspaper budget: "))

result = model.predict([[tv, radio, newspaper]])

print("Predicted Sales:", result[0])

#import csv file

======================================================================

#S203
----------
#S203

import pandas as pd

data = {
    "Name": ["Amit", "Riya", "Karan", "Neha"],
    "Salary": [30000, 40000, 50000, 60000],
    "Experience": [2, 4, 6, 8]
}

df = pd.DataFrame(data)

for i in range(len(df)):

    if df.loc[i, "Experience"] < 5:
        df.loc[i, "Salary"] = df.loc[i, "Salary"] * 1.115
    else:
        df.loc[i, "Salary"] = df.loc[i, "Salary"] * 1.065

print(df)

OUTPUT:
    Name  Salary  Experience
0   Amit   33450           2
1   Riya   44600           4
2  Karan   53250           6
3   Neha   63900           8

======================================================================

#S211
----------
#S211

from sklearn.linear_model import LogisticRegression

x = [[30], [40], [50], [55], [60], [70], [80]]
y = [0, 0, 0, 1, 1, 1, 1]

model = LogisticRegression()
model.fit(x, y)

marks = float(input("Enter marks: "))

result = model.predict([[marks]])

if result[0] == 1:
    print("Eligible for admission")
else:
    print("Not eligible for admission")

OUTPUT:
Enter marks:  34

OUTPUT:
Not eligible for admission

======================================================================

#s212
----------
#s212

import pandas as pd

df = pd.read_csv("item.csv")

print("First 4 rows:")
print(df.head(4))

print("\nShape:")
print(df.shape)

print("\nColumn Names:")
print(df.columns)

print("\nMissing Values:")
print(df.isnull().sum())

print("\nDataset Information:")
print(df.info())

#import csv file

======================================================================

#S221
----------
#S221

def prime(n):

    if n < 2:
        return False

    for i in range(2, n):
        if n % i == 0:
            return False

    return True


num = int(input("Enter a number: "))

if prime(num):
    print("Prime Number")
else:
    print("Not a Prime Number")

OUTPUT:
Enter a number:  1

OUTPUT:
Not a Prime Number

======================================================================

#S222
----------
#S222

import pandas as pd

df = pd.read_csv("employee.csv")

print("First 4 rows:")
print(df.head(4))

print("\nShape:")
print(df.shape)

print("\nColumn Names:")
print(df.columns)

print("\nMissing Values:")
print(df.isnull().sum())

print("\nDataset Information:")
df.info()

#import csv file

======================================================================

#S231
----------
#S231

from sklearn.linear_model import LogisticRegression

x = [[10], [15], [17], [18], [20], [25], [30]]
y = [0, 0, 0, 1, 1, 1, 1]

model = LogisticRegression()
model.fit(x, y)

age = int(input("Enter age: "))

result = model.predict([[age]])

if result[0] == 1:
    print("Eligible to vote")
else:
    print("Not eligible to vote")

OUTPUT:
Enter age:  54

OUTPUT:
Eligible to vote

======================================================================

#S232
----------
#S232

numbers = [10, 20, 30]

print("Original list:", numbers)

numbers.append(40)
print("After append:", numbers)

numbers.extend([50, 60])
print("After extend:", numbers)

numbers.insert(1, 15)
print("After insert:", numbers)

numbers.remove(30)
print("After remove:", numbers)

del numbers[0]
print("After delete:", numbers)

OUTPUT:
Original list: [10, 20, 30]
After append: [10, 20, 30, 40]
After extend: [10, 20, 30, 40, 50, 60]
After insert: [10, 15, 20, 30, 40, 50, 60]
After remove: [10, 15, 20, 40, 50, 60]
After delete: [15, 20, 40, 50, 60]

======================================================================

#S241
----------
#S241

print("Welcome to Artificial Intelligence")

OUTPUT:
Welcome to Artificial Intelligence

======================================================================

#S243
----------
#S243

from sklearn.ensemble import RandomForestClassifier

x = [
    [20, 5],
    [25, 4],
    [30, 2],
    [35, 1],
    [22, 6],
    [40, 2]
]

y = [
    "FIT",
    "FIT",
    "FIT",
    "UNFIT",
    "FIT",
    "UNFIT"
]

model = RandomForestClassifier()
model.fit(x, y)

n = int(input("Enter number of people: "))

for i in range(n):

    age = int(input("Enter age: "))
    exercise = int(input("Enter exercise hours per week: "))

    result = model.predict([[age, exercise]])

    print("Result:", result[0])

OUTPUT:
Enter number of people:  3
Enter age:  23
Enter exercise hours per week:  2

OUTPUT:
Result: FIT

OUTPUT:
Enter age:  34
Enter exercise hours per week:  2

OUTPUT:
Result: FIT

OUTPUT:
Enter age:  2
Enter exercise hours per week:  43

OUTPUT:
Result: FIT

======================================================================

#S251
----------
#S251

text = input("Enter a sentence: ")

words = text.lower().split()

frequency = {}

for word in words:

    if word in frequency:
        frequency[word] = frequency[word] + 1
    else:
        frequency[word] = 1

print("Word Frequency:")

for word in frequency:
    print(word, ":", frequency[word])

OUTPUT:
Enter a sentence:  hello bro

OUTPUT:
Word Frequency:
hello : 1
bro : 1

======================================================================

#S252
----------
#S252

while True:

    user = input("You: ").lower()

    if user == "hello":
        print("Bot: Hello!")

    elif user == "how are you":
        print("Bot: I am fine.")

    elif user == "what is your name":
        print("Bot: I am an AI chatbot.")

    elif user == "bye":
        print("Bot: Goodbye!")
        break

    else:
        print("Bot: Sorry, I don't understand.")

======================================================================
